using System;
using System.Collections.Generic;
using System.Text;
using IGGCore;

namespace IGGConsole
{
    public class ModeDetailedStandingsFormatter : IModeFormatter
    {
        #region IModeFormatter Members

        public void FormatMode(Scoreboard board)
        {
            FormatAdvancedStandingsHeader("NL EAST");
            FormatAdvancedStandingsLine(board.StandingsNLE[0]);
            FormatAdvancedStandingsLine(board.StandingsNLE[1]);
            FormatAdvancedStandingsLine(board.StandingsNLE[2]);
            FormatAdvancedStandingsLine(board.StandingsNLE[3]);
            FormatAdvancedStandingsLine(board.StandingsNLE[4]);
            Console.WriteLine();
            FormatAdvancedStandingsHeader("NL CENTRAL");
            FormatAdvancedStandingsLine(board.StandingsNLC[0]);
            FormatAdvancedStandingsLine(board.StandingsNLC[1]);
            FormatAdvancedStandingsLine(board.StandingsNLC[2]);
            FormatAdvancedStandingsLine(board.StandingsNLC[3]);
            FormatAdvancedStandingsLine(board.StandingsNLC[4]);
            FormatAdvancedStandingsLine(board.StandingsNLC[5]);
            Console.WriteLine();
            FormatAdvancedStandingsHeader("NL WEST");
            FormatAdvancedStandingsLine(board.StandingsNLW[0]);
            FormatAdvancedStandingsLine(board.StandingsNLW[1]);
            FormatAdvancedStandingsLine(board.StandingsNLW[2]);
            FormatAdvancedStandingsLine(board.StandingsNLW[3]);
            FormatAdvancedStandingsLine(board.StandingsNLW[4]);
            Console.WriteLine();
            FormatAdvancedStandingsHeader("AL EAST");
            FormatAdvancedStandingsLine(board.StandingsALE[0]);
            FormatAdvancedStandingsLine(board.StandingsALE[1]);
            FormatAdvancedStandingsLine(board.StandingsALE[2]);
            FormatAdvancedStandingsLine(board.StandingsALE[3]);
            FormatAdvancedStandingsLine(board.StandingsALE[4]);
            Console.WriteLine();
            FormatAdvancedStandingsHeader("AL CENTRAL");
            FormatAdvancedStandingsLine(board.StandingsALC[0]);
            FormatAdvancedStandingsLine(board.StandingsALC[1]);
            FormatAdvancedStandingsLine(board.StandingsALC[2]);
            FormatAdvancedStandingsLine(board.StandingsALC[3]);
            FormatAdvancedStandingsLine(board.StandingsALC[4]);
            Console.WriteLine();
            FormatAdvancedStandingsHeader("AL WEST");
            FormatAdvancedStandingsLine(board.StandingsALW[0]);
            FormatAdvancedStandingsLine(board.StandingsALW[1]);
            FormatAdvancedStandingsLine(board.StandingsALW[2]);
            FormatAdvancedStandingsLine(board.StandingsALW[3]);
            Console.WriteLine();
            FormatAdvancedStandingsHeader("NL WILD CARD");
            FormatAdvancedStandingsLine(board.StandingsNLWC[0]);
            FormatAdvancedStandingsLine(board.StandingsNLWC[1]);
            FormatAdvancedStandingsLine(board.StandingsNLWC[2]);
            FormatAdvancedStandingsLine(board.StandingsNLWC[3]);
            FormatAdvancedStandingsLine(board.StandingsNLWC[4]);
            Console.WriteLine();
            FormatAdvancedStandingsHeader("AL WILD CARD");
            FormatAdvancedStandingsLine(board.StandingsALWC[0]);
            FormatAdvancedStandingsLine(board.StandingsALWC[1]);
            FormatAdvancedStandingsLine(board.StandingsALWC[2]);
            FormatAdvancedStandingsLine(board.StandingsALWC[3]);
            FormatAdvancedStandingsLine(board.StandingsALWC[4]);
            Console.WriteLine();

            Console.CursorLeft = 0;
            Console.CursorTop = 0;
        }

        private void FormatAdvancedStandingsLine(StandingTeam team)
        {
            Console.Write(" ");
            Console.Write(ToolBox.GetFormattedStringPadRight(team.team, 15));
            Console.Write(ToolBox.GetFormattedStringPadRight(team.w.ToString(), 4));
            Console.Write(ToolBox.GetFormattedStringPadRight(team.l.ToString(), 4));
            Console.Write(ToolBox.GetFormattedStringPadRight(team.gb, 5));
            Console.Write(ToolBox.GetFormattedStringPadRight(team.last10, 7));
            Console.Write(ToolBox.GetFormattedStringPadRight(team.strk, 8));
            Console.Write(team.lastg);
            Console.WriteLine();
        }

        private void FormatAdvancedStandingsHeader(string division)
        {
            Console.Write(" ");
            Console.BackgroundColor = ConsoleColor.Gray;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.WriteLine(" "
                + ToolBox.GetFormattedStringPadRight(division, 14)
                + "W   L   GB   L10   STRK     Last Game       ");
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;
        }

        #endregion
    }
}
